package com.zky.gulimall.search.web;

import com.zky.gulimall.search.Service.MallSearchServie;
import com.zky.gulimall.search.vo.SearchParam;
import com.zky.gulimall.search.vo.SearchResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description index
 * @Author 张开源
 * @Date 2022/11/4 22:37
 * @Version 1.0
 **/
@Controller
@Slf4j
public class SearchIndexController {

    @Autowired
    private MallSearchServie mallSearchServie;

    @GetMapping({"/","/list.html"})
    public String indexPage(SearchParam param, Model model, HttpServletRequest request) {
        String queryString = request.getQueryString();
        param.setQueryString(queryString);
        SearchResult result=mallSearchServie.search(param);
        model.addAttribute("result",result);
        return "list";
    }
}
